<template>
  <div>
    <el-container>
        <el-header>
          <!-- 点击展开收起导航和切换对应图标 -->
          <!-- <div class="box_bgd" @click="isC"> 
            <i class="el-icon-s-fold" v-show="block"></i>
            <i class="el-icon-s-unfold" v-show="toggle"></i>
          </div> -->
          <!-- 首页导航栏 -->
          <div class="nav">
            <!-- router：让index作为 path 进行路由跳转 -->
            <el-menu
              router    
              :default-active="$route.path"
              class="el-menu-demo"
              mode="horizontal"
              @select="handleSelect"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b">
              <el-menu-item index="/ucenter2">首页</el-menu-item>
              <el-submenu index="2">
                <template slot="title">工作台</template>
                <!-- <router-link to="/ucenter2/home1"><el-menu-item index="2-1">检测详情</el-menu-item></router-link> -->
                <el-menu-item index="2-1">无</el-menu-item>
                <el-menu-item index="2-2">选项2</el-menu-item>
                <el-menu-item index="2-3">选项3</el-menu-item>
                <el-submenu index="2-4">
                  <template slot="title">选项4</template>
                  <el-menu-item index="2-4-1">选项1</el-menu-item>
                  <el-menu-item index="2-4-2">选项2</el-menu-item>
                  <el-menu-item index="2-4-3">选项3</el-menu-item>
                </el-submenu>
              </el-submenu>
              <el-menu-item index="3" disabled>消息中心</el-menu-item>
              <!-- <el-menu-item index="4"><router-link to="/home1" target="_blank">检测详情</router-link></el-menu-item> -->
              <el-menu-item index="4" disabled>检测详情</el-menu-item>
            </el-menu>
          </div>
          <!-- 设置导航栏右边头像 -->
          <div class="r-content">
            <el-dropdown trigger="hover">
              <!-- <span class="el-dropdown-link">hello! {{this.$store.state.username}}</span> -->
              <span class="el-dropdown-link">hello! {{showUsername}}</span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="$router.push('/ucenter2/usercenter')">个人中心</el-dropdown-item>
                <!-- <el-dropdown-item command='a'>修改密码</el-dropdown-item> -->
                <el-dropdown-item @click.native.prevent="logout()">退出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <!-- <div class="logout">
              <li >
                  <router-link to="/ucenter2/usercenter" title="个人中心">
                  <span class="">个人中心</span>
                  </router-link>
              </li>
              <li style="margin-left:5px">
                  <router-link to="/login" title="退出登录" class="ml5">
                  <span class="">退出</span>
                  </router-link>
              </li> 
          </div> -->
        <!-- <CommonHeader></CommonHeader> -->
        </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="$route.path"
          router
          class="el-menu-vertical"
          background-color="#393e42"
          text-color="#fff"
          active-text-color="rgb(64, 158, 255)"
        >

          <el-submenu index="1">
            <!-- 插槽 插入一级导航标题 -->
            <template slot="title">
            <i class="el-icon-warning"></i>
            <span>系统管理</span>
            </template>
            <!-- 二级导航标题 -->
            <el-menu-item-group>
              <el-menu-item index="/ucenter2/home1">
                  <i class="el-icon-s-shop"></i>检测详情
              </el-menu-item>
              <el-menu-item index="/ucenter2/aimanage">
                  <i class="el-icon-s-flag"></i>设备管理
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
    </el-container>
        
    </el-container>
  </div>
</template>

<script>
import { logout } from '@/api/login'
import Aimanage from './fire/Aimanage'
import Home1 from './fire/Home1'
import Cookies from 'js-cookie';



export default {
  name: "Ucenter2",
  components:{Home1,Aimanage},
  data() {
    return {
    };
  },
  mounted(){
    this.get()
  },
  computed:{
    showUsername(){
      let username = Cookies.get('username')
      return username
    }
  },
  methods: {
    get(){
      var url = window.location.href
      console.log("url=" + url);
    },
    // 动态控制展开与收起和切换对应图标
    isC() {
      this.isCollapse = !this.isCollapse;
      this.toggle = !this.toggle;
      this.block = !this.block;
    },
    handleSelect(key, keyPath) {
        console.log(key, keyPath);
      },
    handleCommand(command) {
      // this.$message('click on item ' + command);
      if(command=="a"){
        this.dialogFormVisible = true;
      }
    },
    logout(){
      logout().then(response=>{
        console.log(response);
        if(response.data && response.data.code==200){
          //退出登录，清空token
          localStorage.removeItem('eleToken');
          this.$router.push({path:'/login'})
          this.$message.success('退出成功')
        }
      })
      .catch(err=>{})
    }
  }

  // exit() {
  //     this.$confirm('此操作将注销登录, 是否继续?', '提示', {
  //       confirmButtonText: '确定',
  //       cancelButtonText: '取消',
  //       type: 'warning'
  //     }).then(() => {
  //       sessionStorage.removeItem("user")
  //       this.$router.push('/login')
  //     }).catch(() => {
  //       this.$message({
  //         type: 'info',
  //         message: '已取消操作'
  //       });
  //     });
  //   }
};
</script>

<style scoped>
.el-header {
  background-color: #b3c0d1;
  color: #fff;
  line-height: 60px;
  height: 100%;
  padding: 0 !important;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}
.el-menu {
  border-right-width: 0;
}
.el-main {
  color: #333;
}
body > .el-container {
    margin-bottom: 40px;
}
.el-menu-vertical:not(.el-menu--collapse) {
  width: 240px;
}
.box_bgd {
  height: 60px;
  float: left;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 54px;
}
.box_bgd i {
  font-size: 20px;
}
.box_bgd:hover {
  background-color: rgb(203, 215, 230);
}
.nav {
  float: left;
  width: 500px;
  height: 60px;
}
.r-content{
  float: right;
}
.logout{
  float: right;
  list-style: none;
  width: 200px;
  height: 60px;
  background-color: #545c64;
  color:#333;
}
.logout li{
    float: left;
    margin: 0 10px;
}
</style>
